package com.example.myproject.client;

import java.util.ArrayList;

public class ModuleMeasures {

	static int getCenterOfX(ArrayList<Module> modArray) {
		int x = 0;
		for (Module mod : modArray) {
			x += mod.getX();
		}
		int xCoord = x / modArray.size();		
		return xCoord;
	}
	
	static int getCenterOfY(ArrayList<Module> modArray) {
		int y = 0;
		for (Module mod : modArray) {
			y += mod.getY();
		}
		int yCoord = y / modArray.size();	
		return yCoord;
	}
	
	static Coordinate getCenterOfModules(ArrayList<Module> modArray) {
		int x = 0;
		int y = 0;
		for (Module mod : modArray) {
			x += mod.getX();
			y += mod.getY();
		}
		int xCoord = x / modArray.size();
		int yCoord = y / modArray.size();
		return new Coordinate(xCoord, yCoord);
	}
	
	static int calcDistance(Coordinate coord1, Coordinate coord2) {
		return calcDistance(coord1.getX(), coord1.getY(), coord2.getX(), coord2.getY());
	}
	
	/**
	 * Calculates taxicab distance from coordinate to another coordinate.
	 * @param x1 X coordinate for point 1
	 * @param y1 Y coordinate for point 1
	 * @param x2 X coordinate for point 2
	 * @param y2 Y coordinate for point 2
	 * @return
	 */
	static int calcDistance(int x1, int y1, int x2, int y2) {
		int distance;
		if (x1 < x2) {
			distance = x2 - x1;
		} else {
			distance = x1 - x2;
		}
		if (y1 < y2) {
			distance += y2 - y1;
		} else {
			distance += y1 - y2;
		}
		return distance;
	}
	
	static int totalMovement(ArrayList<Module> modArray, HabitatLayout layout) {
		// TODO
		
		return 0;
	}	
	
	static double layoutOptimization(Layouts layout) {

		// TODO: count used vs unused mods, floating mods, blah blah blah...
		
		return 0.0;
	}
}
